﻿using FluentValidation;
using FluentValidation.Attributes;
using Quickie.Models;
using Quickie.Models.IoC;
using Quickie.Models.Data;
using Quickie.Models.Entities;
using Quickie.Models.ViewModel;
using Quickie.Models.Interfaces;

namespace Quickie.Models.Entities
{
    /// <summary>
    /// Klasa koja predstavlja entitet Product
    /// Partial jer je vec preko L2S definirana u .dbml 
    /// datoteci. Atribut se odnosi na Fluent Validation validator
    /// </summary>
    [Validator(typeof(ProductValidation))]
    public partial class Product : IEntity
    {
       
    }

    /// <summary>
    /// Klasa koja predstavlja validator za klasu Product
    /// </summary>
    public class ProductValidation : AbstractValidator<Product>
    {
        /// <summary>
        /// Provjere ispravnosti unosa/izmjene kategorija
        /// </summary>
        public ProductValidation()
        {
            RuleFor(x => x.Name)
                .NotEmpty()
                .WithMessage("Unesite naziv proizvoda");

            RuleFor(x => x.Price)
                .NotNull()
                .WithMessage("Cijena ne smije biti 0");

            
            RuleFor(x => x.CategoryID)
                .NotNull()
                .GreaterThan(0)
                .WithMessage("Morate odabrati kategoriju");
        }

    }
}
